﻿using Core.Extended;
using Core.Store;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Utils;

namespace Infrastructure.ExtendedEntities
{
    public class Store_Category_WithProperties : Store_Category, IStoreCategory, IExtended<Store_Category, Store_Category_WithProperties>
    {
        public Store_Category_WithProperties()
        {
        }

        public Store_Category_WithProperties(Store_Category category, string cultureName)
        {
            ClassHelpers.CopyAllProperties<Store_Category, Store_Category_WithProperties>(category, this);
            this.CultureName = cultureName;
        }

        public Store_Category_WithProperties MapParentClassObject(Store_Category classObject, string lang)
        {
            return new Store_Category_WithProperties(classObject, lang);
        }

        private string _name;

        public string Name
        {
            get
            {
                if (String.IsNullOrWhiteSpace(this.CultureName) || this.Store_CategoryMainProperty == null || this.Store_CategoryMainProperty.Count == 0)
                {
                    return _name;
                }
                else
                {
                    return this.Store_CategoryMainProperty.With(x => x.SingleOrDefault(y => y.Culture.Name == CultureName).Name);
                }
            }
            set
            {
                if (String.IsNullOrWhiteSpace(this.CultureName) || this.Store_CategoryMainProperty == null || this.Store_CategoryMainProperty.Count == 0)
                {
                    _name = value;
                }
                else
                {
                    this.Store_CategoryMainProperty.SingleOrDefault(x => x.Culture.Name == CultureName).Name = value;
                }
            }
        }

        public string Description
        {
            get
            {
                if (String.IsNullOrWhiteSpace(this.CultureName) || this.Store_CategoryMainProperty.Count == 0)
                {
                    return String.Empty;
                }
                else
                {
                    return this.Store_CategoryMainProperty.With(x => x.SingleOrDefault(y => y.Culture.Name == CultureName).Description);
                }
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public string CultureName
        {
            get;
            set;
        }

        public bool IsNewImage
        {
            get;
            set;
        }
    }
}
